'''
类的创建
(1)属性
(2)方法
(3)对象实例化
(4)构造函数、一个析构函数
(5)类属性
(6)公共属性
(7)对象属性
(8)私有属性，私有方法
(9)内置成员
(10)重写内置成员
(11)类方法
(12)私有属性访问和赋值

class Student:
    name = "huang" #类属性

    def study(self,courseName):
        print("study course:%s"%courseName)

#实例化对象
stu = Student()
print(stu.name)
print(Student.name)

stu.study("A")

stu1 = Student()
print(stu1.name)
'''
import datetime

class Student:
    #类属性
    stu_count = 0

    #公共属性
    @property
    def area(self):
        area = "ShangHai"
        return area

    #构造函数
    def __init__(self,id,name,data_of_birth):
        self.id = id #对象属性
        self.name = name
        self.data_of_birth = data_of_birth
        self.__year_of_birth = data_of_birth[0:4] #私有属性,__属性
        self.age = self.__get_age()
        Student.stu_count += 1

    #私有方法(__方法名)
    def __get_age(self):
        now_year = datetime.datetime.now().year
        age = now_year - int(self.__year_of_birth)
        return age


    #对象方法
    def study(self,course):
        print("area:{0}\t id:{1}\t name:{2}\t course:{3}\t age:{4}".format(self.area,self.id,self.name,course,self.age))
        
    #析构函数
    def __del__(self):
        Student.stu_count -= 1

    #重写方法__str__
    def __str__(self):
        return "student imformation!"

    #类方法
    @staticmethod
    def display_stu_count():
        print("count of the student:%d"% Student.stu_count)
        
    #私有属性的访问
    def get_score(self):
        return self.__score
    
    def set_score(self,score):
        if score >= 0 and score <= 100:
            self.__score = score
        else:
            print("arguments is error")


    

#主程序
stu1 = Student("f23015126","hyx","2005/02/22")
print("count:%d"% Student.stu_count) #类名.类属性名
stu1.study("Python")
print(stu1.name)

#对象属性访问/赋值
stu1.id = "23003"  #对象.属性名
stu1.name = "joker"
stu1.data_of_birth = "2005/03/16"
stu1.study("math") #对象.方法名

stu2 = Student("f23015220","hhw","20050514")
print("count:%d"% Student.stu_count)
stu2.study("C")

#重写内置方法调用
print(str(stu2))

#类方法调用
Student.display_stu_count()

#私有属性赋值访问
stu2.set_score(95)
print("score:%d"%stu2.get_score())

del stu1
print("count:%d"% Student.stu_count)

